// var i;
// var AL_GAME_HUA_Instance = require("./AL_GAME_HUA_Instance");
// var AL_GAME_HUA_Common = require("./AL_GAME_HUA_Common");
// var AL_GAME_HUA_Define = require("./AL_GAME_HUA_Define");
// var AL_GAME_HUA_PopupSelf = require("./AL_GAME_HUA_PopupSelf");
// var AL_GAME_HUA_ToggleCustom = require("./AL_GAME_HUA_ToggleCustom");
// var AL_GAME_HUA_AddPrefab = require("./AL_GAME_HUA_AddPrefab");
// var AL_GAME_HUA_EmailData = require("./AL_GAME_HUA_EmailData");
// var AL_GAME_HUA_ButtonEnabled = require("./AL_GAME_HUA_ButtonEnabled");
// var AL_GAME_HUA_PayConfig = require("./AL_GAME_HUA_PayConfig");
// var P = cc._decorator;
// var g = P.ccclass;
// var y = P.property;
// var m = (function (e) {
//     function t() {
//         var t = (null !== e && e.apply(this, arguments)) || this;
//         t.music_Toggle = null;
//         t.sound_Toggle = null;
//         t.vibrate_Toggle = null;
//         t.node_pause = null;
//         t.node_home = null;
//         t.node_home_bg = null;
//         t.node_pause_bg = null;
//         t.node_return = null;
//         t.node_toggle_debug = null;
//         t.node_red_dot = null;
//         t.label_email = null;
//         t.state_Button = null;
//         t.node_button_code = null;
//         t.options = null;
//         return t;
//     }
//     __extends(t, e);
//     t.prototype.onLoad = function () {
//         var t = this;
//         if (e.prototype.onLoad) {
//             e.prototype.onLoad.call(this);
//         }
//         ailin_sdk_manager.addListenerBackKey({
//             node: this.node,
//             callBack: function () {
//                 t.handle_event_button_click_back();
//             }
//         });
//         this.chushihua_tiaoshi_kaiguan();
//     };
//     t.prototype.start = function () {
//         this.music_Toggle.isChecked = AL_APP_SDK_MANAGER.yinyue_kaiguan_zhuangtai;
//         this.sound_Toggle.isChecked = AL_APP_SDK_MANAGER.yinxiao_kaiguan_zhuangtai;
//         this.vibrate_Toggle.isChecked = AL_APP_SDK_MANAGER.zhendong_zhuangtai;
//     };
//     t.prototype.chushihua_tiaoshi_kaiguan = function () {
//         var e = 0;
//         var t = null;
//         this.node_toggle_debug.on(
//             cc.Node.EventType.TOUCH_END,
//             function () {
//                 null == t || Date.now() - t < 1e3
//                     ? (e++,
//                       (t = Date.now()),
//                       e >= 30 &&
//                           ((AL_GAME_HUA_Common.Common.secretDebug = !AL_GAME_HUA_Common.Common.secretDebug),
//                           AL_GAME_HUA_Common.Common.secretDebug
//                               ? AL_APP_SDK_MANAGER.showToast("开启调试模式")
//                               : AL_APP_SDK_MANAGER.showToast("关闭调试模式"),
//                           AL_APP_SDK_MANAGER.emit("debugChange", AL_GAME_HUA_Common.Common.secretDebug),
//                           (e = 0),
//                           (t = null)))
//                     : ((t = null), (e = 0));
//             },
//             this
//         );
//     };
//     t.prototype.zhixing_chushihua_chuli = function (e) {
//         var t = this;
//         this.options = e;
//         this.node_pause.active = e.isGame;
//         this.node_home.active = !e.isGame;
//         this.node_home_bg.active = !e.isGame;
//         this.node_pause_bg.active = e.isGame;
//         e.isGame
//             ? AL_GAME_HUA_Instance.Instance.xianshi_dingbu_tiao({
//                   showVit: !0,
//                   target: this.node
//               })
//             : (AL_APP_SDK_MANAGER.on(
//                   AL_GAME_HUA_Define.GameEvent.REFRESH_EMAIL_LIST,
//                   function () {
//                       t.shuaxin_youjian_liebiao();
//                   },
//                   this
//               ),
//               this.shuaxin_youjian_liebiao(),
//               this.state_Button.shezhi_anniu_jiaohuxing(AL_GAME_HUA_PayConfig.PayConfig.getInstance().huoqu_zhifu_shifou_youxiao()));
//     };
//     t.prototype.shuaxin_youjian_liebiao = function () {
//         var e = AL_GAME_HUA_EmailData.EmailData.getInstance().huoqu_weidu_youjian();
//         this.node_red_dot.active = e.length > 0;
//         this.label_email.string = e.length.toString();
//     };
//     t.prototype.handle_event_button_click_back = function () {
//         if (this.options.onClose) {
//             this.options.onClose();
//         }
//         this.close();
//     };
//     t.prototype.handle_toggle_callback = function (e, t) {
//         switch (t) {
//             case "musicTg":
//                 AL_APP_SDK_MANAGER.yinyue_kaiguan_zhuangtai = e.isChecked;
//                 break;
//             case "soundTg":
//                 AL_APP_SDK_MANAGER.yinxiao_kaiguan_zhuangtai = e.isChecked;
//                 break;
//             case "vibrateTg":
//                 AL_APP_SDK_MANAGER.zhendong_zhuangtai = e.isChecked;
//         }
//     };
//     t.prototype.handle_event_button_click_return = function () {
//         if (this.options.onHome) {
//             this.options.onHome();
//         }
//         this.close();
//     };
//     t.prototype.handle_event_button_click_angle = function () {
//         var e = this;
//         AL_GAME_HUA_Instance.Instance.jiancha_tili_shifou_zugou(function () {
//             if (e.options.onRestart) {
//                 e.options.onRestart();
//             }
//             e.close();
//         });
//     };
//     t.prototype.handle_event_button_click_email = function () {
//         AL_GAME_HUA_AddPrefab.AddPrefab.chuangjian_youjian_mianban();
//     };
//     t.prototype.handle_event_button_click_code = function () {
//         AL_GAME_HUA_AddPrefab.AddPrefab.chuangjian_duihuanma_mianban();
//     };
//     t.prototype.handle_event_button_click_state = function () {
//         AL_GAME_HUA_AddPrefab.AddPrefab.chuangjian_zhuangtai_mianban();
//     };
//     t.prototype.onEnable = function () {
//         AL_APP_SDK_MANAGER.emit(AL_GAME_HUA_Define.GameEvent.ON_GAME_CLUB_HIDE, {
//             node: this.node,
//             hide: !0
//         });
//     };
//     t.prototype.onDisable = function () {
//         AL_APP_SDK_MANAGER.emit(AL_GAME_HUA_Define.GameEvent.ON_GAME_CLUB_HIDE, {
//             node: this.node,
//             hide: !1
//         });
//     };
//     t.prototype.onDestroy = function () {
//         AL_APP_SDK_MANAGER.off(this);
//     };
//     __decorate([y(AL_GAME_HUA_ToggleCustom.default)], t.prototype, "music_Toggle", void 0);
//     __decorate([y(AL_GAME_HUA_ToggleCustom.default)], t.prototype, "sound_Toggle", void 0);
//     __decorate([y(AL_GAME_HUA_ToggleCustom.default)], t.prototype, "vibrate_Toggle", void 0);
//     __decorate([y(cc.Node)], t.prototype, "node_pause", void 0);
//     __decorate([y(cc.Node)], t.prototype, "node_home", void 0);
//     __decorate([y(cc.Node)], t.prototype, "node_home_bg", void 0);
//     __decorate([y(cc.Node)], t.prototype, "node_pause_bg", void 0);
//     __decorate([y(cc.Node)], t.prototype, "node_return", void 0);
//     __decorate([y(cc.Node)], t.prototype, "node_toggle_debug", void 0);
//     __decorate([y(cc.Node)], t.prototype, "node_red_dot", void 0);
//     __decorate([y(cc.Label)], t.prototype, "label_email", void 0);
//     __decorate([y(AL_GAME_HUA_ButtonEnabled.default)], t.prototype, "state_Button", void 0);
//     __decorate([y(cc.Node)], t.prototype, "node_button_code", void 0);
//     return __decorate([g], t);
// })(AL_GAME_HUA_PopupSelf.default);
// exports.default = m;


const AL_GAME_HUA_Instance = require("./AL_GAME_HUA_Instance");
const AL_GAME_HUA_Common = require("./AL_GAME_HUA_Common");
const AL_GAME_HUA_Define = require("./AL_GAME_HUA_Define");
const AL_GAME_HUA_PopupSelf = require("./AL_GAME_HUA_PopupSelf");
const AL_GAME_HUA_ToggleCustom = require("./AL_GAME_HUA_ToggleCustom");
const AL_GAME_HUA_AddPrefab = require("./AL_GAME_HUA_AddPrefab");
const AL_GAME_HUA_EmailData = require("./AL_GAME_HUA_EmailData");
const AL_GAME_HUA_ButtonEnabled = require("./AL_GAME_HUA_ButtonEnabled");
const AL_GAME_HUA_PayConfig = require("./AL_GAME_HUA_PayConfig");

const { ccclass, property } = cc._decorator;

/**
 * 主界面管理类
 */
@ccclass
class MainUI extends AL_GAME_HUA_PopupSelf.default {
    @property(AL_GAME_HUA_ToggleCustom.default) music_Toggle = null;
    @property(AL_GAME_HUA_ToggleCustom.default) sound_Toggle = null;
    @property(AL_GAME_HUA_ToggleCustom.default) vibrate_Toggle = null;
    @property(cc.Node) node_pause = null;
    @property(cc.Node) node_home = null;
    @property(cc.Node) node_home_bg = null;
    @property(cc.Node) node_pause_bg = null;
    @property(cc.Node) node_return = null;
    @property(cc.Node) node_toggle_debug = null;
    @property(cc.Node) node_red_dot = null;
    @property(cc.Label) label_email = null;
    @property(AL_GAME_HUA_ButtonEnabled.default) state_Button = null;
    @property(cc.Node) node_button_code = null;

    /** 加载完成时调用 */
    onLoad() {
        super.onLoad && super.onLoad();
        ailin_sdk_manager.addListenerBackKey({
            node: this.node,
            callBack: () => this.handle_event_button_click_back()
        });
        this.chushihua_tiaoshi_kaiguan();
    }

    /** 开始时调用 */
    start() {
        this.music_Toggle.isChecked = AL_APP_SDK_MANAGER.yinyue_kaiguan_zhuangtai;
        this.sound_Toggle.isChecked = AL_APP_SDK_MANAGER.yinxiao_kaiguan_zhuangtai;
        this.vibrate_Toggle.isChecked = AL_APP_SDK_MANAGER.zhendong_zhuangtai;
    }

    /** 初始化调试开关 */
    chushihua_tiaoshi_kaiguan() {
        let clickCount = 0;
        let zuihou_dianji_shijian = null;
        this.node_toggle_debug.on(
            cc.Node.EventType.TOUCH_END,
            () => {
                const now = Date.now();
                if (!zuihou_dianji_shijian || now - zuihou_dianji_shijian < 1000) {
                    clickCount++;
                    zuihou_dianji_shijian = now;
                    if (clickCount >= 30) {
                        AL_GAME_HUA_Common.Common.secretDebug = !AL_GAME_HUA_Common.Common.secretDebug;
                        AL_APP_SDK_MANAGER.showToast(AL_GAME_HUA_Common.Common.secretDebug ? "开启调试模式" : "关闭调试模式");
                        AL_APP_SDK_MANAGER.emit("debugChange", AL_GAME_HUA_Common.Common.secretDebug);
                        clickCount = 0;
                        zuihou_dianji_shijian = null;
                    }
                } else {
                    zuihou_dianji_shijian = null;
                    clickCount = 0;
                }
            },
            this
        );
    }

    /** 初始化UI状态 */
    zhixing_chushihua_chuli(options) {
        this.options = options;
        this.node_pause.active = options.isGame;
        this.node_home.active = !options.isGame;
        this.node_home_bg.active = !options.isGame;
        this.node_pause_bg.active = options.isGame;

        if (options.isGame) {
            AL_GAME_HUA_Instance.Instance.xianshi_dingbu_tiao({
                showVit: true,
                target: this.node
            });
        } else {
            AL_APP_SDK_MANAGER.on(AL_GAME_HUA_Define.GameEvent.REFRESH_EMAIL_LIST, () => this.shuaxin_youjian_liebiao(), this);
            this.shuaxin_youjian_liebiao();
            this.state_Button.shezhi_anniu_jiaohuxing(AL_GAME_HUA_PayConfig.PayConfig.getInstance().huoqu_zhifu_shifou_youxiao());
        }
    }

    /** 刷新邮件列表 */
    shuaxin_youjian_liebiao() {
        const unreadEmails = AL_GAME_HUA_EmailData.EmailData.getInstance().huoqu_weidu_youjian();
        this.node_red_dot.active = unreadEmails.length > 0;
        this.label_email.string = unreadEmails.length.toString();
    }

    /** 返回按钮点击处理 */
    handle_event_button_click_back() {
        if (this.options.onClose) {
            this.options.onClose();
        }
        this.close();
    }

    /**
     * 处理切换按钮的回调
     * @param {cc.Toggle} toggle
     * @param {string} type
     */
    handle_toggle_callback(toggle, type) {
        switch (type) {
            case "musicTg":
                AL_APP_SDK_MANAGER.yinyue_kaiguan_zhuangtai = toggle.isChecked;
                break;
            case "soundTg":
                AL_APP_SDK_MANAGER.yinxiao_kaiguan_zhuangtai = toggle.isChecked;
                break;
            case "vibrateTg":
                AL_APP_SDK_MANAGER.zhendong_zhuangtai = toggle.isChecked;
                break;
        }
    }

    /** 返回主页按钮点击处理 */
    handle_event_button_click_return() {
        if (this.options.onHome) {
            this.options.onHome();
        }
        this.close();
    }

    /** 重新开始按钮点击处理 */
    handle_event_button_click_angle() {
        AL_GAME_HUA_Instance.Instance.jiancha_tili_shifou_zugou(() => {
            if (this.options.onRestart) {
                this.options.onRestart();
            }
            this.close();
        });
    }

    /** 点击邮件按钮 */
    handle_event_button_click_email() {
        AL_GAME_HUA_AddPrefab.AddPrefab.chuangjian_youjian_mianban();
    }

    /** 点击代码按钮 */
    handle_event_button_click_code() {
        AL_GAME_HUA_AddPrefab.AddPrefab.chuangjian_duihuanma_mianban();
    }

    /** 点击状态按钮 */
    handle_event_button_click_state() {
        AL_GAME_HUA_AddPrefab.AddPrefab.chuangjian_zhuangtai_mianban();
    }

    /** 启用时调用 */
    onEnable() {
        AL_APP_SDK_MANAGER.emit(AL_GAME_HUA_Define.GameEvent.ON_GAME_CLUB_HIDE, {
            node: this.node,
            hide: true
        });
    }

    /** 禁用时调用 */
    onDisable() {
        AL_APP_SDK_MANAGER.emit(AL_GAME_HUA_Define.GameEvent.ON_GAME_CLUB_HIDE, {
            node: this.node,
            hide: false
        });
    }

    /** 销毁时调用 */
    onDestroy() {
        AL_APP_SDK_MANAGER.off(this);
    }
}

exports.default = MainUI;
